<?php

class Solution
{
    /**
     * @param Integer[][] $matrix
     */
    function setZeroes(&$matrix)
    {
        //存放需要设置为0的 行 => 列
        $zeroRow = [];
        $zeroCol = [];
        foreach ($matrix as $tr => $row) {
            foreach ($row as $td => $val) {
                if ($val == 0) {
                    $zeroRow[] = $tr;
                    $zeroCol[] = $td;
                }
            }
        }

        foreach ($matrix as $tr => &$row) {
            foreach ($row as $td => &$val) {
                if (in_array($tr, $zeroRow)) {
                    $val = 0;
                }
                if (in_array($td, $zeroCol)) {
                    $val = 0;
                }
            }
        }
    }
}
